package com.nettest.action.demo;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.beans.factory.annotation.Autowired;

import com.nettest.action.BaseJsonAction;
import com.nettest.bean.BaseCriteriaVo;
import com.nettest.entity.demo.Grid50000;
import com.nettest.service.demo.Grid50000Service;

@Results({
		@Result(name = "input", type = "json", params = { "ignoreHierarchy",
				"false", "excludeNullProperties", "true", "excludeProperties",
				"drid50000Service" }),
		@Result(name = "success", location = "/demo/_content.html") })
public class DemoAction extends BaseJsonAction {

	private static final long serialVersionUID = 7796054923782630546L;
	private String item_nm;
	private String item_cd;

	private List<Grid50000> lists;
	@Autowired
	private Grid50000Service drid50000Service;

	public DemoAction() {
		super();
	}

	@SuppressWarnings("unchecked")
	@Action(value = "getItems", results = { @Result(name = "success", type = "json", params = {
			"ignoreHierarchy", "false", "excludeNullProperties", "true",
			"excludeProperties", "item_nm,item_cd" }) })
	public String getItems() {
		int intPage = getPage();
		int intRows = getRows();
		int firstResult = intPage * intRows - intRows + 1;
		BaseCriteriaVo critera = new BaseCriteriaVo();
		critera.setPageSize(firstResult);
		critera.setPageSize(intRows);
		critera.setSortField(getSort());
		critera.setDescOrAsc(getOrder());
		
		try {
			this.lists = (List<Grid50000>)drid50000Service.queryByCriteria(critera);
			setTotal(drid50000Service.totalSize(critera));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public String getItem_nm() {
		return item_nm;
	}

	public void setItem_nm(String item_nm) {
		this.item_nm = item_nm;
	}

	public String getItem_cd() {
		return item_cd;
	}

	public void setItem_cd(String item_cd) {
		this.item_cd = item_cd;
	}
	@JSON(name="rows")
	public List<Grid50000> getLists() {
		return lists;
	}

	public void setLists(List<Grid50000> lists) {
		this.lists = lists;
	}
}